package leetcode.剑指offer.剑指II;

import leetcode.剑指offer.pojo.ListNode;
import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/18 20:33
 * @description：https://leetcode-cn.com/problems/3u1WK4/
 */
public class 两个链表的第一个重合节点 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    public class Solution {
        public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
            ListNode A = headA;
            ListNode B = headB;
            while (A != null || B != null) {
                if (A == B) break;
                A = A == null ? headB : A.next;
                B = B == null ? headA : B.next;
            }
            return A;
        }
    }
}
